package com.esun.cheetah.biz.personal.attention;

import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;

import com.esun.cheetah.biz.match.matchlist.MatchListManager;
import com.esun.cheetah.biz.personal.personalinfo.UserInfo;
import com.esun.cheetah.config.BizCode;
import com.esun.cheetah.config.Config;
import com.esun.cheetah.config.Key;
import com.esun.cheetah.model.match.matchlist.Match;
import com.esun.cheetah.network.AbsInferiorityCommunicater;

import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;

/**
 * 添加用户关注比赛 com.esun.cheetah.biz.personal.attentation.AddAttentionMatch
 * 
 * @author 任付江€ &lt;br/&gt; create at 2012-4-23 下午1:59:39
 */
public class AddAttentionMatch extends AbsInferiorityCommunicater {
	/** 用户名 */
	private String userName;
	/** 采种 */
	private String lotid;
	/** 对阵Id **/
	private String matchid;
	/** 主队 */
	private String home;
	/** 客队 */
	private String away;
	/** 开始时间 */
	private String begintime;
	/** json对象 */
	private JSONObject json;

	private Match match;
	
	public JSONObject getJson() {
		return json;
	}

	public void setJson(JSONObject json) {
		this.json = json;
	}

	public AddAttentionMatch(Handler handler) {
		super(handler);
	}

	public AddAttentionMatch(Handler handler, String userName, String lotid,
			String matchid, String home, String away, String begintime) {
		this(handler);
		
		if(!TextUtils.isEmpty(UserInfo.getUserInfo().getCk())){
			this.userName = UserInfo.getUserInfo().getUserName();
		}
		
		this.lotid = lotid;
		this.matchid = matchid;
		this.home = home;
		this.away = away;
		this.begintime = begintime;	
	}
	
	public AddAttentionMatch(Handler handler, Match match , String lotid){
		super(handler);
		
		this.lotid = lotid;
		this.userName = "testphone";
		this.matchid = match.getMatchId();
		this.home = match.getHomeName();
		this.away = match.getAwayName();
		this.begintime =match.getMatchDate()+" "+ match.getMatchTime()+":00";
		this.match = match;
	}

	@Override
	public HashMap<String, String> comHashMap() {
		HashMap<String, String> hashMapAddAttenTeam = new HashMap<String, String>();
		hashMapAddAttenTeam.put(Key.KEY_ID, BizCode.BIZCODE_MATCH);
		if(!TextUtils.isEmpty(userName)){
			hashMapAddAttenTeam.put(Key.KEY_USERNAME, userName);
		}
		hashMapAddAttenTeam.put(Key.KEY_LOTID, lotid);
		hashMapAddAttenTeam.put(Key.KEY_MATC_ID, matchid);
		hashMapAddAttenTeam.put(Key.KEY_HOME, home);
		hashMapAddAttenTeam.put(Key.KEY_AWAY, away);
		hashMapAddAttenTeam.put(Key.KEY_BEGINTIME, begintime);
		return hashMapAddAttenTeam;
	}

	@Override
	public void getJsonContent(String serverRes) throws JSONException {
		json = new JSONObject(serverRes);
		this.setJson(json);
	}

	@Override
	public void getServerResponseFail(String serverRes) {
		Message msg = handlerFromAct
				.obtainMessage(Config.COMMON_INFO_MSG_20002);
		handlerFromAct.sendMessage(msg);
	}

	@Override
	public void getServerResponseSuccess() {
		//AttentionListManager.getInstance().setAttentionListAdded(true);

		Message msg = handlerFromAct
				.obtainMessage(Config.COMMON_INFO_MSG_20001);
		msg.obj = match;
		handlerFromAct.sendMessage(msg);
	}

	@Override
	public void getServerResponseException() {
		Message msg = handlerFromAct
				.obtainMessage(Config.COMMON_INFO_MSG_20003);
		handlerFromAct.sendMessage(msg);
	}

}
